package com.example.Cairodio;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

/**
 * This class offers a detailed view for each element in the 
 * application gallery
 * @author AnwaRowers
 *
 */
public class GalleryItemActivity extends Activity{

	Uri [] paths;
	int currentIndex;
	int max;
	int pointer; 
	ImageView imgView;
	
	 public void onCreate(Bundle savedInstanceState) {
		 super.onCreate(savedInstanceState);
		 setContentView(R.layout.gallery_item);
		 paths = MyGallery.uris;
		 imgView = (ImageView)findViewById(R.id.GalleryItem);
		 Bundle extras = getIntent().getExtras();
		 currentIndex = extras.getInt("current");
		 max = extras.getInt("max");		 
		 imgView.setImageURI(paths[currentIndex]);
	 }
	
	 /**
	  * go to the next image in the gallery
	  * @param view
	  */
	 public void previous(View view) {
		 pointer += (max-1);
		 pointer %= max; 
		 imgView.setImageURI(paths[pointer]);
	 }
	 
	 /**
	  * go to the previous image in the gallery
	  * @param view
	  */
	 public void next(View view) {
		 pointer++;
		 pointer %= max; 
		 imgView.setImageURI(paths[pointer]);
	 }
	 
	 /**
	  * initiates a new instance of the Gallery Activity.
	  * @param view
	  */
	 public void toGallery(View view) {
	    	Intent intent = new Intent().setClass(GalleryItemActivity.this,
					MyGallery.class);
	    	startActivity(intent);
	 }
}
